<?php

namespace App\Admin\Actions\Post;

use App\Models\Good;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class GoodsListSmall extends LazyRenderable
{
    public function grid(): Grid
    {
        // 获取外部传递的参数
        return Grid::make(new Good(), function (Grid $grid) {
            $grid->column('id');
            $grid->column('goods_name', '商品名称');
            $grid->column('goods_stock', '库存');
            $grid->column('goods_price', '商品实际价格');
            $grid->column('goods_image', '商品图片')->image('', 100, 100);
            $grid->column('goods_status', '商品状态')->using(['1' => '上架', '0' => '下架']);
            //下架不让选中
            $grid->rowSelector()->disable(function ($row) {
                return $row->goods_status === 0;
            });

            //$grid->rowSelector()->disable(function ($disable) {
            //	return $disable->id === $this->id ;
            //});

            //$grid->column('goods_type')->display(function ($e) {
            //	$data = GoodsType::where('id', $this->goods_type)->pluck('name');
            //	return $data[0];
            //});
            $grid->column('created_at');
            $grid->column('updated_at');
            // 指定行选择器选中时显示的值的字段名称
            // 指定行选择器选中时显示的值的字段名称
            // 指定行选择器选中时显示的值的字段名称
            // 如果表格数据中带有 “name”、“title”或“username”字段，则可以不用设置
            $grid->rowSelector()->titleColumn('goods_name');
            $grid->paginate(9);
            $grid->disableActions();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('goods_name')->width(4);
                $filter->like('name')->width(4);
            });
        });
    }
}